﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ProjectTest.Models
{
    public class QLQuyen
    {
        DBTestDataContext db = new DBTestDataContext();
        //lay len toan bo thong tin cac quyen
        public IEnumerable<Quyen> GetAll()
        {
            return db.Quyens;
        }
        //them quyen
        public void Create(Quyen q)
        {
            try
            {
                db.Quyens.InsertOnSubmit(q);
                db.SubmitChanges();
            }
            catch (Exception)
            {
                
                throw;
            }
        }
        //sua quyen
        public void Edit(Quyen qEdited,int ma)
        {
            Quyen q = db.Quyens.SingleOrDefault(p => p.MaQuyen == ma);
            try
            {
                UpdateInfo(q, qEdited);
                db.SubmitChanges();
            }
            catch (Exception)
            {
                
                throw;
            }
        }

        private void UpdateInfo(Quyen q, Quyen qEdited)
        {
            q.MoTa = q.MoTa;
        }
        //xoa quyen
        public void Delete(int ma)
        {
            Quyen q = db.Quyens.SingleOrDefault(p => p.MaQuyen == ma);
            try
            {
                db.Quyens.DeleteOnSubmit(q);
                db.SubmitChanges();
            }
            catch (Exception)
            {
                
                throw;
            }
        }

    }
}